package ee.serge;

public class KnapsackObject implements Comparable<KnapsackObject> {

   private int price;
   private int weight;
   
   public KnapsackObject(int price, int weight) {
      this.price = price;
      this.weight = weight;
   }
   
   public int getPrice() {
      return price;
   }
   
   public int getWeight() {
      return weight;
   }
   
   public float getValue() {
      return (float) ((float)price / weight);
   }

   @Override
   public int compareTo(KnapsackObject o) {
      float value = getValue();
      float oValue = o.getValue();
      if (value < oValue) return 1;
      else if (value > oValue) return -1;
      return 0;
   }

   @Override
   public String toString() {
      return "KnapsackObject [price=" + price + ", weight=" + weight + "]";
   }
   
}
